
***********
clear
clear matrix
clear mata
set maxvar 20000 
set more off
************



global dir0="DATA/"
global dir1="TABLES/"
global dir3="PLOTS/"

log using "${dir1}log_tables.log", replace


*** DEFINE GLOBAL DEMO
global demo1 "pop_2001 sh_pop_20_34_01 sh_pop_more urbanization unempl2001"
global demo2 "share_diploma distcapo  diffworkerspc_96 diffimpresepc_96 firms_pc_01 workers_pc_01"



clear
set more off
use "${dir0}Data_national_regs.dta", clear

*************************************************************
*							REGRESSIONS						*
*************************************************************


* * ** * ** * ** * ** * ** * ** * ** * ** * *
* * *DEFINE GLOBALS
* * ** * ** * ** * ** * ** * ** * ** * ** * *
global out="turnout"
global ols="internet"
global sort="internet"
global keep="internet"
global iv="(internet=distance_closest_SGUXpost2001)"
global instrument="distance_closest_SGUXpost2001"
global if="if year<2012 & year>1994"

global controls_first="pop regi_*"
global controls="pop regi_*"
global poly1="poly1a_*"
global poly2="poly1a_* poly2a_*"
global iter1="inter1_*"
global iter2="inter1_* inter2_*"



global ols_placebo="internet_a"
global iv_placebo="(internet_a=dist_closest_SGUXpostplacebo)"
global keep_placebo="internet_a"
global instrument_placebo="dist_closest_SGUXpostplacebo"



global sort="internet years_since_good_internet dum4goodinternet dum0goodinternet"
global keep="internet years_since_good_internet dum4goodinternet dum0goodinternet"

global ols2="years_since_good_internet"
global iv2="(years_since_good_internet=distance_closest_SGUXpost2001)"


global ols3="dum4goodinternet"
global iv3="(dum4goodinternet=distance_closest_SGUXpost2001)"

global ols4="dum0goodinternet"
global iv4="(dum0goodinternet=distance_closest_SGUXpost2001)"


global if_nourb="if urbanization<3 &  year<2012 & year>1994"
global if_nosgu="if distance_closest_SGU>0 &  year<2012 & year>1994"

global if_young="if sh_pop_more<=bottomquartile_shpopmore &  year<2012 & year>1994"
global if_old="if sh_pop_more>topquartile_shpopmore &  year<2012 & year>1994"

global poly1_no_urb="poly1a_pop_2001 poly1a_sh_pop_20_34_01 poly1a_sh_pop_more poly1a_unempl2001"

* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * *





***********************
* Table 1 - Framework *
***********************

***************************************************
* Table 2 - Turnout Results: 1996-2008 (Baseline) *
***************************************************
local i=1
foreach var of varlist $out {
xi: xtreg  `var' $ols $controls $if, fe cluster(province)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 $ols using "${dir1}tab2", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
xi: xtreg $ols $instrument $controls_first $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $controls $if, fe  first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab2", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep) addstat(F, `F1')

xi: xtreg $ols $instrument $poly1 $controls_first $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $poly1 $controls $if, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab2", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1') 
 
 
xi: xtreg $ols $instrument $poly1 $poly2 $controls_first $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $poly1 $poly2 $controls $if, fe first cluster(province) partial(regi_*)
outreg2 $ols using "${dir1}tab2", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  

xi: xtreg $ols $instrument $iter1 $controls_first $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $iter1 $controls $if, fe first cluster(province) partial(regi_*)
outreg2 $ols using "${dir1}tab2", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1') 

xi: xtreg $ols $instrument $iter1 $iter2 $controls_first $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $iter1 $iter2 $controls $if, fe first cluster(province) partial(regi_*)
outreg2 $ols using "${dir1}tab2", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1') 
}


**********************************************
* Table 3 - Placebo regressions (pre-trend) *
**********************************************


local i=1
foreach var of varlist $out {
xi: xtreg  `var' $ols_placebo $controls $if, fe cluster(province)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2  using "${dir1}tab3", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep_placebo)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
xi: xtreg $ols_placebo $instrument_placebo $controls_first $if, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2  `var' $iv_placebo $controls $if, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab3", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep_placebo)   addstat(F, `F1') 

xi: xtreg $ols_placebo $instrument_placebo $poly1 $controls_first $if, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2  `var' $iv_placebo $poly1 $controls $if, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab3", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep_placebo)   addstat(F, `F1') 

xi: xtreg $ols_placebo $instrument_placebo $poly1 $poly2 $controls_first $if, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2  `var' $iv_placebo $poly1 $poly2 $controls $if, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab3", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep_placebo)   addstat(F, `F1') 
}



*****************************************************
* Table 4 - Turnout Results: 1996-2008 (Robustness) *
*****************************************************

* Sub-samples by age profile
pctile quartile=sh_pop_more if year==2001, nq(4)
egen bottomquartile_shpopmore = min(quartile)
egen topquartile_shpopmore = max(quartile)
drop quartile


local i=1
foreach var of varlist $out {
* Alternative specification: non-urban municipalities
xi: xtreg $ols $instrument $controls_first $poly1_no_urb $if_nourb, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv $controls $poly1_no_urb $if_nourb, fe first cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tab4", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep) addstat(F, `F1')  
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
* Alternative specification: municipalities without SGU
xi: xtreg $ols $instrument $controls_first $poly1 $if_nosgu, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv $controls $poly1 $if_nosgu, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab4", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  


* Alternative specification: years since good internet as independent variable
xi: xtreg $ols2 $instrument $controls_first $poly1 $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv2 $controls $poly1 $if, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab4", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  

* Alternative specification: dummy for full internet access (>4) as independent variable
xi: xtreg $ols3 $instrument $controls_first $poly1 $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv3 $controls $poly1 $if, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab4", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  

* Alternative specification: dummy for any internet access (>0) as independent variable
xi: xtreg $ols4 $instrument $controls_first $poly1 $if, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv4 $controls $poly1 $if, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab4", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1') 
 
* Below 25th percentile for over-65 population
xi: xtreg $ols $instrument $controls_first $poly1 $if_young, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv $controls $poly1 $if_young, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab4", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  

* Above 75the percentile for over-65 population 
xi: xtreg $ols $instrument $controls_first $poly1 $if_old, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv $controls $poly1 $if_old, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab4", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  
}



********************************************
* Table 5 - Turnout Long-Run Results: 2013 *
********************************************

global if1_lr="if year==1996 | year==2001 | year>2012"
global if_nourb_lr="if urbanization<3 &  (year==1996 | year==2001 | year>2012)"

global sort="internet years_since_good_internet dum4goodinternet dum0goodinternet"
global keep="internet years_since_good_internet dum4goodinternet dum0goodinternet"

local i=1
foreach var of varlist $out {
xi: xtreg $ols $instrument $controls_first $poly1 $if_lr, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv $controls $poly1 $if1_lr, fe first cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tab5", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
* Alternative specification: non-urban municipalities
xi: xtreg $ols $instrument $controls_first $poly1_no_urb $if_nourb_lr, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv $controls $poly1_no_urb $if_nourb_lr, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab5", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  


* Alternative specification: years since good internet as independent variable
xi: xtreg $ols2 $instrument $controls_first $poly1 $if_lr, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv2 $controls $poly1 $if1_lr, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab5", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  

* Alternative specification: non-urban municipalities; years since good internet as independent variable
xi: xtreg $ols2 $instrument $controls_first  $poly1_no_urb $if_nourb_lr, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv2 $controls $poly1_no_urb $if_nourb_lr, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab5", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')
  
* Alternative specification: dummy for full internet access (>4) as independent variable
xi: xtreg $ols3 $instrument $controls_first $poly1  $if_lr, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv3 $controls $poly1 $if1_lr, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab5", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1') 
 
* Alternative specification: dummy for any internet access (>0) as independent variable
xi: xtreg $ols4 $instrument $controls_first $poly1 $if_lr, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var'  $iv4 $controls $poly1 $if1_lr, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab5", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  
}



****************************************************
* Table 6 - Turnout Full Sample Results: 1996-2013 *
****************************************************

global if_all="if year>=1996"


local i=1
foreach var of varlist $out {
xi: xtreg  `var' $ols $controls $if_all, fe cluster(province)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2  using "${dir1}tab6", tex  bdec(3)  nocons label keep($keep)  $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}

xi: xtreg $ols $instrument $controls_first $if_all, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $controls $if_all, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab6", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  

xi: xtreg $ols $instrument $poly1 $controls_first $if_all, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $poly1 $controls_first $if_all, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab6", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  

xi: xtreg $ols $instrument $poly1 $poly2 $controls $if_all, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $poly1 $poly2 $controls $if_all, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab6", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1') 

xi: xtreg $ols $instrument $iter1 $controls_first $if_all, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $iter1 $controls $if_all, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab6", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  


xi: xtreg $ols $instrument $iter1 $iter2 $controls_first $if_all, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $iter1 $iter2 $controls $if_all, fe first cluster(province) partial(regi_*)
outreg2  using "${dir1}tab6", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep)  addstat(F, `F1')  
}


************************************************
* Table 7 - Coalition Regressions: 2001 & 2008 *
************************************************

global out="votes_center_right votes_center_left votes_outsiders"
global out2="abs_votes_center_right abs_votes_center_left abs_votes_outsiders"

global sort="internet years_since_good_internet dum4goodinternet dum0goodinternet"
global keep="internet years_since_good_internet dum4goodinternet dum0goodinternet"

global if_2001_2008="if (year==2001 | year==2008) & region_code!=4"


local i=1
foreach var of varlist $out {
xi: xtreg $ols $instrument $poly1  $controls_first $if_2001_2008, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $poly1  $controls $if_2001_2008, fe cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tab7", tex  bdec(3)  nocons label keep($keep)  addstat(F, `F1')   $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
}




local i=1
foreach var of varlist $out2 {
xi: xtreg $ols $instrument $poly1   $controls_first $if_2001_2008, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv $poly1 $controls $if_2001_2008, fe first cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tab7_(votes_per_eligible_voters)", tex  bdec(3)  nocons label keep($keep)  addstat(F, `F1')   $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
}



************************************************
* Table 8 - Coalition Regressions: 2001 & 2013 *
************************************************
replace abs_votes_M5S=0 if year==2001
replace abs_votes_CIVIC_MONTI=0 if year==2001
replace abs_votes_FARE=0 if year==2001


global out="abs_votes_M5S abs_votes_center_right abs_votes_center_left abs_votes_outsiders abs_votes_FARE abs_votes_CIVIC_MONTI "
global iv2="(years_since_good_internet=distance_closest_SGUXpost2001)"
global if_2001_2013="if (year==2001 | year>2012) & region_code!=4"

preserve
keep if year==2013 & region_code!=4
foreach var of varlist $out{
sum `var' 
}
restore


local i=1
foreach var of varlist $out {
xi: xtreg $ols $instrument $poly1  $controls_first $if_2001_2013, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv2 $poly1 $controls $if_2001_2013, fe first cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tab8", tex  bdec(3)  nocons label keep($keep)  addstat(F, `F1')   $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
}


************************************************
* Table 9 - M5S ** Groups and Membership 
******************************************

***********
clear
clear matrix
clear mata
set maxvar 20000 
set more off
set matsize 10000
************
* M5S Membership
*Dep. variable: Days since first group

use "${dir0}Data_meetups_1.dta", clear


global sort="internet"
global keep="internet"
global instrument_nopost="distance_closest_SGU"


xi: ivreg logdayssince (internet=distance_closest_SGU) $demo1 $demo2  i.province i.sll2001, cluster(province)
outreg2 using "${dir1}tab9", tex  bdec(3)  nocons label keep($keep)  replace sortvar($sort)


**************
* Panel Number of Meetup Members per City-Year
**************
use "${dir0}Data_meetups_2.dta", clear

global out_m5s="num_aff_year_city_per1000"

foreach var of varlist $out_m5s {
xtivreg2 `var' (internet=distance_closest_SGUXpost2001) pop poly1a_*  regi_* , fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tab9", tex  bdec(3)  nocons label keep($keep)   append sortvar($sort)
}


************************************************
* Table 10 -* Municipal Elections *
************************************************

***********
clear
clear matrix
clear mata
set maxvar 20000 
set more off
set matsize 10000
************
use "${dir0}Data_Municipal_Elections.dta", clear



global if_mun_year="if year>=2008 & year<2012"

global if_mun_year2="if year>=2008 & year<=2012"

global keep="internet years_since_good_internet"
global sort="internet years_since_good_internet"

global instrument_nopost="distance_closest_SGU"

rename province province_code

global out_mun="elections_w_grillo abs_grilloshare_party2"

local i=1
foreach var of varlist $out_mun {
xi: ivreg2 `var' (internet=distance_closest_SGU)  $demo1 i.year i.province_code i.sll2001 $if_mun_year, cluster(province_code) first partial(i.year i.province_code i.sll2001)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tab10", tex  bdec(3)  nocons label keep($keep)  $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
xi: ivreg2  `var' (years_since_good_internet=distance_closest_SGU)  $demo1 i.year i.province_code i.sll2001 $if_mun_year2, cluster(province_code) first partial(i.year i.province_code i.sll2001)
outreg2 using "${dir1}tab10", tex  bdec(3)  nocons label keep($keep)     $append sortvar($sort)
}





*********************************************
**************APPENDIX *************
*********************************************

*********************************************
* Descriptive statistics *
*********************************************

***TABLE A1
use "${dir0}Data_national_regs.dta", clear
preserve
keep if year==1996
sutex2  turnout abs_votes_center_right abs_votes_center_left abs_votes_outsiders, min dig(2) varlab replace sav(${dir1}tab_A1) 
restore

preserve
keep if year==2001
sutex2  turnout abs_votes_center_right abs_votes_center_left abs_votes_outsiders, min dig(2) varlab append sav(${dir1}tab_A1) 
restore

preserve
keep if year==2006
sutex2  turnout abs_votes_center_right abs_votes_center_left abs_votes_outsiders, min dig(2) varlab append sav(${dir1}tab_A1) 
restore

preserve
keep if year==2008
sutex2  turnout abs_votes_center_right abs_votes_center_left abs_votes_outsiders, min dig(2) varlab append sav(${dir1}tab_A1) 
restore

preserve
keep if year==2013
sutex2  turnout abs_votes_center_right abs_votes_center_left abs_votes_outsiders, min dig(2) varlab append sav(${dir1}tab_A1) 
restore



***TABLE A2
use "${dir0}Data_national_regs.dta", clear

preserve
keep if year==2006
sutex2  internet years_since_good_internet dum0goodinternet dum4goodinternet, min dig(2) varlab replace sav(${dir1}tab_A2) 
restore

preserve
keep if year==2008
sutex2  internet years_since_good_internet dum0goodinternet dum4goodinternet, min dig(2) varlab append sav(${dir1}tab_A2) 
restore

preserve
keep if year==2013
sutex2  internet years_since_good_internet dum0goodinternet dum4goodinternet, min dig(2) varlab append sav(${dir1}tab_A2) 
restore


***TABLE A3

use "${dir0}Data_national_regs.dta", clear
sutex2 $demo1 $demo2 distance_closest_SGU, min dig(2) varlab replace sav(${dir1}tab_A3) 


use "${dir0}Data_national_regs.dta", clear

***********************************************************
* Table A4 -  *
***********************************************************
gen pop2001_1000 = pop_2001/1000

pwcorr internet turnout pop2001_1000 $demo1 $demo2 if year==2006, sig
pwcorr internet turnout pop2001_1000 $demo1 $demo2 if year==2008, sig


*****************************************
* Table A5 - Turnout Results: 1994-2008 *
*****************************************

local i=1
foreach var of varlist turnout {
xi: xtreg `var' internet pop regi_* if year<2012 & year>=1994, fe cluster(province)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tabA5", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
xi: xtreg $ols $instrument  pop regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var' (internet=distance_closest_SGUXpost2001) pop regi_* if year<2012 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA5", tex  bdec(3)  nocons label $append sortvar($sort) keep($keep) addstat(F, `F1')


xi: xtreg $ols $instrument  pop poly1a_* regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var' (internet=distance_closest_SGUXpost2001) pop poly1a_* regi_* if year<2012 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA5", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 

xi: xtreg $ols $instrument  pop poly1a_* poly2a_* regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var' (internet=distance_closest_SGUXpost2001) pop poly1a_* poly2a_* regi_* if year<2012 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA5", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 

xi: xtreg $ols $instrument  pop inter1_* regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var' (internet=distance_closest_SGUXpost2001) pop inter1_*  regi_* if year<2012 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA5", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 

xi: xtreg $ols $instrument  pop inter1_* inter2_* regi_* if year<2012 & year>=1994, fe  cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 `var' (internet=distance_closest_SGUXpost2001) pop inter1_* inter2_* regi_* if year<2012 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA5", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 
}





*********************************************************
* Table A6 - Placebo regressions (pre-trend): 1994-2008 *
*********************************************************
global ols_placebo="internet_a"
global iv_placebo="(internet_a=dist_closest_SGUXpostplacebo)"
global keep_placebo="internet_a"
global instrument_placebo="dist_closest_SGUXpostplacebo"



local i=1
foreach var of varlist turnout {
xi: xtreg turnout internet_a pop regi_* if year<2002 & year>=1994, fe cluster(province)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tabA6", tex  bdec(3)  nocons label keep($keep_placebo)  $append sortvar($sort_placebo) 
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
xi: xtreg $ols_placebo $instrument_placebo pop  regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2 turnout (internet_a=dist_closest_SGUXpostplacebo) pop regi_* if year<2002 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA6", tex  bdec(3)  nocons label keep($keep_placebo)   $append sortvar($sort_placebo)   addstat(F, `F1') 


xi: xtreg $ols_placebo $instrument_placebo pop poly1a_* regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2 turnout (internet_a=dist_closest_SGUXpostplacebo) pop poly1a_* regi_* if year<2002 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA6", tex  bdec(3)  nocons label keep($keep_placebo)   $append sortvar($sort_placebo)   addstat(F, `F1') 

xi: xtreg $ols_placebo $instrument_placebo pop poly1a_* poly2a_* regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2 turnout (internet_a=dist_closest_SGUXpostplacebo) pop poly1a_* poly2a_* regi_* if year<2002 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA6", tex  bdec(3)  nocons label keep($keep_placebo)   $append sortvar($sort_placebo)   addstat(F, `F1') 

xi: xtreg $ols_placebo $instrument_placebo pop inter1_* regi_*  if year<2012 & year>=1994, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2 turnout (internet_a=dist_closest_SGUXpostplacebo) pop inter1_*  regi_* if year<2002 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA6", tex  bdec(3)  nocons label keep($keep_placebo)   $append sortvar($sort_placebo)   addstat(F, `F1') 

xi: xtreg $ols_placebo $instrument_placebo pop inter1_* inter2_*  regi_* if year<2012 & year>=1994, fe cluster(province) 
test $instrument_placebo
local F1=r(F)
xtivreg2 turnout (internet_a=dist_closest_SGUXpostplacebo) pop inter1_* inter2_* regi_* if year<2002 & year>=1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA6", tex  bdec(3)  nocons label keep($keep_placebo)   $append sortvar($sort_placebo)   addstat(F, `F1') 

}




****************************************************
* Table A7 - Turnout Results: 1996-2008 (Weighted) *
****************************************************


local i=1
foreach var of varlist turnout {
xi: xtreg turnout internet pop regi_* [aw=pop_2001] if year<2012 & year>1994, fe cluster(province)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tabA7", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort) 
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}

* Basic IV
xi: xtreg $ols $instrument pop  regi_* [aw=pop_2001]  if year<2012 & year>1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 turnout (internet=distance_closest_SGUXpost2001) pop regi_* [aw=pop_2001] if year<2012 & year>1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA7", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 


xi: xtreg $ols $instrument pop poly1a_*  regi_* [aw=pop_2001]  if year<2012 & year>1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 turnout (internet=distance_closest_SGUXpost2001) pop poly1a_* regi_* [aw=pop_2001] if year<2012 & year>1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA7", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 


xi: xtreg $ols $instrument pop poly1a_* poly2a_*  regi_*  [aw=pop_2001]  if year<2012 & year>1994, fe  cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 turnout (internet=distance_closest_SGUXpost2001) pop poly1a_* poly2a_* regi_* [aw=pop_2001] if year<2012 & year>1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA7", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 

xi: xtreg $ols $instrument pop inter1_* regi_* [aw=pop_2001]  if year<2012 & year>1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 turnout (internet=distance_closest_SGUXpost2001) pop inter1_*  regi_* [aw=pop_2001] if year<2012 & year>1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA7", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 

xi: xtreg $ols $instrument pop inter1_* inter2_*  regi_*  [aw=pop_2001]  if year<2012 & year>1994, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2 turnout (internet=distance_closest_SGUXpost2001) pop inter1_* inter2_* regi_* [aw=pop_2001] if year<2012 & year>1994, fe first cluster(province) partial(regi_*)
outreg2 using "${dir1}tabA7", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 

}





************************************************
* Table A8 - Coalition Regressions with years since good broadband: 2001 & 2008 *
************************************************

global out="votes_center_right votes_center_left votes_outsiders"
global out2="abs_votes_center_right abs_votes_center_left abs_votes_outsiders"

global sort="internet years_since_good_internet dum4goodinternet dum0goodinternet"
global keep="internet years_since_good_internet dum4goodinternet dum0goodinternet"

global if_2001_2008="if (year==2001 | year==2008) & region_code!=4"


local i=1
foreach var of varlist $out {
xi: xtreg $ols2 $instrument $poly1  $controls_first $if_2001_2008, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv2 $poly1 $controls $if_2001_2008, fe first cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tabA8", tex  bdec(3)  nocons label keep($keep)  addstat(F, `F1')   $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
}


local i=1
foreach var of varlist $out2 {
xi: xtreg $ols2 $instrument $poly1   $controls_first $if_2001_2008, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' $iv2 $poly1 $controls $if_2001_2008, fe first cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tabA8_(votes_per_eligible_voters)", tex  bdec(3)  nocons label keep($keep)  addstat(F, `F1')   $append sortvar($sort)
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
}

*******************************
* Table A9: Party Regressions *
*******************************
global out_party="abs_votes_PDL abs_votes_LEGA abs_votes_PD abs_votes_IDV abs_votes_FASC_OUT abs_votes_COM_OUT"


local i=1
foreach var of varlist $out_party {
xi: xtreg $ols $instrument pop poly1a_* regi_* $if_2001_2008, fe cluster(province) 
test $instrument
local F1=r(F)
xtivreg2  `var' (internet=distance_closest_SGUXpost2001) pop poly1a_* regi_* $if_2001_2008, fe cluster(province) partial(regi_*)
if `i'==1 {
   global append="replace"
}
else {
   global append="append" 
}
outreg2 using "${dir1}tabA9", tex  bdec(3)  nocons label keep($keep)   $append sortvar($sort)   addstat(F, `F1') 
local i=`i'+1
if `i'==1 {
   global append="replace" 
}
else {
   global append="append"
}
}

sum abs_votes_PDL $if_2001_2008
sum abs_votes_LEGA $if_2001_2008
sum abs_votes_PD $if_2001_2008
sum abs_votes_IDV $if_2001_2008
sum abs_votes_FASC_OUT $if_2001_2008
sum abs_votes_COM_OUT $if_2001_2008


*******************************
* Table A10,11 : Party aggregations
*******************************


*******************************
* Table A.12: Frequency of Facebook Use and Online Political Engagement
*******************************
clear
use "${dir0}itanes_2013.dta"

**drop if no info on facebook use
drop if d73==-1 | d73==5 

gen facebook_frequency=5-d73

***ONLINE ENGAGEMENT

*********** OLS
preserve
*D72_4. Condividere contenuti (testi, foto, video, immagini) relativi alla campagna elettorale
codebook d72_4
drop if d72_4==-1 | d72_4==5 | d72_4==6

gen online_sharing_camp_cont=5-d72_4

foreach var of varlist online_sharing_camp_cont {
codebook `var' 
reg  `var' facebook_frequency independent   self_pos_extr_right self_pos_cent_right self_pos_center self_pos_cent_left  bad_econ_cond educ fam employed married sex age read_news  unempl_rate_2011 pop_density_2011 share_female_pop_2011 share_foreign_pop_2011 share_pop_between_20_40_2011 distance_closest_capoluogo i.region [pw=weight],  r cluster(province_code)
outreg2 using "${dir1}tabA12", tex  bdec(3)  nocons label   replace keep(facebook_frequency)
}

restore



preserve
*D72_5. Partecipare a discussioni on line su questioni politiche e/o sulla campagna
codebook d72_5
drop if d72_5==-1 | d72_5==5 | d72_5==6


gen engage_online_discus=5-d72_5

foreach var of varlist engage_online_discus {
codebook `var' 
reg  `var' facebook_frequency independent   self_pos_extr_right self_pos_cent_right self_pos_center self_pos_cent_left  bad_econ_cond educ fam employed married sex age read_news  unempl_rate_2011 pop_density_2011 share_female_pop_2011 share_foreign_pop_2011 share_pop_between_20_40_2011 distance_closest_capoluogo i.region [pw=weight],  r cluster(province_code)
outreg2 using "${dir1}tabA12", tex  bdec(3)  nocons label keep(facebook_frequency)   append  
}
restore




*D72_6. Partecipare a un evento o a una manifestazione politica dopo avere ricevuto un invito via internet
preserve

codebook d72_6
drop if d72_6==-1 | d72_6==5 | d72_6==6

gen partic_online_event=5-d72_6

foreach var of varlist partic_online_event {
codebook `var' 
reg  `var' facebook_frequency independent   self_pos_extr_right self_pos_cent_right self_pos_center self_pos_cent_left  bad_econ_cond educ fam employed married sex age read_news  unempl_rate_2011 pop_density_2011 share_female_pop_2011 share_foreign_pop_2011 share_pop_between_20_40_2011 distance_closest_capoluogo i.region [pw=weight],  r cluster(province_code)
outreg2 using "${dir1}tabA12", tex  bdec(3)  nocons label  append keep(facebook_frequency)
}

restore

